package com.p2p.backend.service.impl;

import java.util.List;
import java.util.Map;

import org.apache.commons.collections.MapUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.p2p.backend.dao.BackUserDao;
import com.p2p.backend.dao.UserRoleDao;
import com.p2p.backend.service.RealBackUserService;
import com.p2p.base.util.MergeUtil;

/**
 * leiwen@yiqihao.com
 */
@Service("realBackUserService")
public class RealUserServiceImpl implements RealBackUserService {

	@Autowired
	private BackUserDao realUserDao;
	@Autowired
	private UserRoleDao userRoleDao;

	@Override
	public void add(Map<String, Object> user) {
		realUserDao.addBackUser(user);
		user.put("user_id", user.get("id"));
		userRoleDao.add(user);
	}

	@Override
	public void update(Map<String, Object> user) {
		realUserDao.updateBackUser(user);
		user.put("user_id", user.get("id"));
		userRoleDao.update(user);
	}

	@Override
	public List<Map<String, Object>> listAll() {
		return realUserDao.listAll();
	}

	@Override
	public Map<String, Object> getDetail(Integer id) {
		Map<String, Object> user = realUserDao.getBackUser(id);
		Map<String, Object> role = userRoleDao.get(id);
		MergeUtil.merge(user, role,"ur_");
		return user;
	}

}
